import { useDispatch } from "react-redux";
import { Content } from "./components/Content/Content";
import { Footer } from "./components/Footer/footer";
import { Header } from "./components/Header/header";
import { login } from "./store/userStore";
import { useEffect } from "react";
import { message } from "antd";
import { reqWhoAmI } from "./api/userApi";
import { reqGetAllTypes } from "./api/typeApi";
import { setTypeList } from "./store/typeStore";

export default function App(){
    const dispatch = useDispatch()
    const getAllType = async () => {
        const { data } = await reqGetAllTypes()
        dispatch(setTypeList(data))
    }
    const whoAMI = async () => {
        const { code, data } = await reqWhoAmI()
        if ( code === 0 ){
            dispatch(login(data))
            messageApi.success(`欢迎回来,${data.nickname}`)
        }else{
            // 报错
        }
    }
    useEffect(()=>{
        whoAMI()
        getAllType()
    },[])
    const [messageApi,contextHold] = message.useMessage()
    return (
        <>
            {/*Header*/}
            <Header/>
            {/*Content*/}
            <Content/>
            {/*Footer*/}
            <Footer/>
            {contextHold}
        </>
    )
}